﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm_2.Easy_590_Postorder
{
    public class Node
    {
        public int val;
        public IList<Node> children;

        public Node() { }

        public Node(int _val)
        {
            val = _val;
        }

        public Node(int _val, IList<Node> _children)
        {
            val = _val;
            children = _children;
        }
    }
    class MainProject
    {
        static void Main(string[] args)
        {
            //foreach (var item in FindRestaurant(new string[] { "Shogun", "Tapioca Express", "Burger King", "KFC" }, new string[] { "Piatti", "The Grill at Torrey Pines", "Hungry Hunter Steakhouse", "Shogun" }))
            //{
            //    Console.WriteLine(item);
            //}
            Console.ReadKey();
        }
        public static IList<int> Postorder(Node root)
        {
            IList<int> list = new List<int>();
            if (root == null) return list;
            DFS(list, root);
            return list;
        }

        private static void DFS(IList<int> list, Node root)
        {
            foreach (var item in root.children) DFS(list, item);
            list.Add(root.val);
        }
    }
}
